﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoForChessFromTC
{
    /// <summary>
    ///  游戏类
    /// </summary>
    class Game
    {
        private const int Cols = 8;
        private const int Rows = 8;
        //此处8行8列以小方块为单元（block)，而不是像五子棋一样分界线作行列
        private const int GameWidth = 1000;
        private const int GameHeight = 1000;
        private bool NextIsBlack;

        /// <summary>
        /// 所有块类的集合
        /// </summary>
        private List<Block> Blocks { get; set; }
        //定义一个集合，其中成员为Block

        public Game( )
        {
            NextIsBlack = true;
            //初始化集合
            Blocks = new List<Block>();//Block为所有块类的集合
            for (int i = 0; i < Rows; i++)
            {
                //行遍历
                for (int j = 0; j < Cols; j++)
                {
                    //列遍历
                    Block block = new Block(new Point(i, j));
                    //把正在遍历的这一个加到集合中
                    Blocks.Add(block);
                }
            }
            //仍处于初始阶段
            //以下画出游戏开始时棋盘上的4枚两黑两白（成对角）的棋子
            Blocks[27].Status = BlockStatus.White;
            Blocks[36].Status = BlockStatus.White;
            Blocks[28].Status = BlockStatus.Black;
            Blocks[35].Status = BlockStatus.Black;

        }

        /// <summary>
        /// 绘制当前游戏场景
        /// </summary>
        /// <param name="g">绘图句柄</param>
        /// <param name="size">游戏区域尺寸</param>
        public void Draw(Graphics g, Size size)
        {
            //指定位图大小
            Image img = new Bitmap(GameWidth, GameHeight);
            Graphics _g = Graphics.FromImage(img);
            _g.DrawImage(Properties.Resources.bg, new Rectangle(0,0,GameWidth,GameHeight));
            //bg为非深浅区域的背景图，大小与游戏区域尺寸同
            
            foreach (var block in Blocks) 
            {
                //对每个Blocks集合中的block变量
                block.Draw(_g);
                //调用Game成员的Draw方法
            }

            //画背景
            Rectangle rec = new Rectangle(new Point(0, 0), size);
            g.DrawImage(img, rec);

        }
    }
}

